package com.wxy.care.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wxy.care.KnnUtils.Instance;
import com.wxy.care.KnnUtils.KNN;
import com.wxy.care.entity.Count;
import com.wxy.care.entity.Sensor;
import com.wxy.care.mapper.CountMapper;
import com.wxy.care.service.CountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.*;
@Slf4j
@Service
public class CountServiceImpl extends ServiceImpl<CountMapper, Count> implements CountService {
    @Autowired
    private KNN knn;
    @Autowired
    private CountService countService;
    public double sort(Sensor sensor){
        //sensor.getMachineId();
        LambdaQueryWrapper<Count> queryWrapper = new LambdaQueryWrapper();
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime thirtyMinutesAgo = now.minusMinutes(30);
        queryWrapper.eq(Count::getSlaveId,sensor.getSlaveId())
                .between(Count::getDate,thirtyMinutesAgo,now);
        double count = this.count(queryWrapper);
        return count;
    }
//    public String prepare(List<Sensor> sensors){
//        Map<String,Double> map = new TreeMap<>(new Comparator<String>() {
//            @Override
//            public int compare(String o1, String o2) {
//                return o1.compareTo(o2);
//            }
//        });
//        Calendar calendar = Calendar.getInstance();
//        int hour = calendar.get(Calendar.HOUR_OF_DAY); // 获取小时数（24小时制）
////        int minute = calendar.get(Calendar.MINUTE); // 获取分钟数
////        int second = calendar.get(Calendar.SECOND); // 获取秒数
//// 将时分秒转化为时间戳格式
////        double timestamp = hour * 3600 + minute * 60 + second;
//        map.put("时间",(double) hour);
////        List<Double>db = new ArrayList<>();
//        for(Sensor sensor : sensors){
//            //类别
//            Double sort = sort(sensor);
//            Integer place = sensor.getPlace();
//            map.put(place,sort);
//        }
//        System.out.println(map);
//        List<Double>db = new ArrayList<>();
//        for (Map.Entry<String, Double> entry : map.entrySet()) {
//            Double value = entry.getValue();
//            db.add(value);
//        }
//        Double[] db1 = db.toArray(new Double[0]);
//        double[] db2 = new double[db1.length];
//        for (int i = 0; i < db1.length; i++) {
//            db2[i] = db1[i].doubleValue();  // 将每个 Double 对象转换成 double 类型
//        }
//        for (double i : db2)
//            System.out.print(i +" ");
//        Instance instance = new Instance(db2,"");
//        String prediction = knn.predict(instance);
//        return prediction;
//    }
}
